package com.ruicar.afs.cloud.afscase.approvetask.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruicar.afs.cloud.afscase.approvetask.service.WorkTaskPoolHistoryService;
import com.ruicar.afs.cloud.afscase.approvetask.vo.TaskHistoryCondition;
import com.ruicar.afs.cloud.afscase.infomanagement.entity.CaseBaseInfo;
import com.ruicar.afs.cloud.afscase.infomanagement.service.CaseBaseInfoService;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


/**
 * @Description 审批历史
 * @Author Peng_Jinbo
 * @Date 2020/06/08 14:01
 */
@RestController
@RequestMapping("/taskHistory")
@Slf4j
@AllArgsConstructor
public class TaskHistoryController {

    private WorkTaskPoolHistoryService workTaskPoolHistoryService;
    private CaseBaseInfoService caseBaseInfoService;

    @GetMapping("/listHistoryContent")
    public IResponse listHistoryContent(@ModelAttribute TaskHistoryCondition condition) {
        if(! condition.isCheck() && caseBaseInfoService.checkNormalFlowEnd(condition.getApplyNo())) {
            CaseBaseInfo baseInfo = caseBaseInfoService.getOne(
                    Wrappers.<CaseBaseInfo>lambdaQuery()
                        .eq(CaseBaseInfo::getApplyNo,condition.getApplyNo())
            );
            if(StrUtil.isNotBlank(baseInfo.getNormalApproveFlowId())){
                condition.setStageId(baseInfo.getNormalApproveFlowId());
            }
        }
        return IResponse.success(workTaskPoolHistoryService.listHistoryContent(condition.getStageId()));
    }
}
